//
//  BookCellView.m
//  handbooklite
//
//  Created by bao_wsfk on 12-8-31.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BookCellView.h"

@implementation BookCellView

@synthesize title =_title;
@synthesize titleLabelBackgroundView =_titleLabelBackgroundView;
@synthesize progressView =_progressView;
@synthesize backgroundView =_backgroundView;

- (void)dealloc{
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame 
{
    if ((self = [super initWithFrame:frame])) {
        // Background view
        self.backgroundView = [[[UIView alloc] initWithFrame:CGRectNull] autorelease];
        self.backgroundView.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:self.backgroundView];
        
        // Label
        self.titleLabelBackgroundView = [[[UIView alloc] initWithFrame:CGRectNull] autorelease];
        self.titleLabelBackgroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
        
        self.title = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
        self.title.textAlignment = UITextAlignmentRight;
        self.title.backgroundColor = [UIColor clearColor];
        self.title.textColor = [UIColor whiteColor];
        self.title.font = [UIFont systemFontOfSize:12];
        
        [self.titleLabelBackgroundView addSubview:self.title];
        [self addSubview:self.titleLabelBackgroundView];
        
    }
    
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    int labelHeight = 30;
    int labelInset = 5;
    
    // Background view
    self.backgroundView.frame = self.bounds;
    self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    // Layout title
    self.titleLabelBackgroundView.frame = CGRectMake(0, 
                                                    0, 
                                                    self.bounds.size.width, 
                                                    labelHeight);
    self.titleLabelBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    // Layout title background
    CGRect f = CGRectMake(0, 
                          0, 
                          self.title.superview.bounds.size.width,
                          self.title.superview.bounds.size.height);
    self.title.frame = CGRectInset(f, labelInset, 0);
    self.title.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

- (UIProgressView *)startProgress{
    //progress
    self.progressView =[[[UIProgressView alloc] initWithFrame:CGRectNull] autorelease];
    //Layout progressView
    self.progressView.frame =CGRectMake(0, self.bounds.size.height-20,self.bounds.size.width, 10);
    [self.progressView setProgress:0.5];
    [self.progressView setProgressViewStyle:UIProgressViewStyleDefault];
    [self.progressView setProgressTintColor:[UIColor greenColor]];
    [self.progressView setTrackTintColor:[UIColor grayColor]];
    [self addSubview:self.progressView];
    return self.progressView;
}

- (void)endProgress{
    [self.progressView removeFromSuperview];
}

@end
